import * as path from 'path';

export default (app) => {

    app.beforeStart(async () => {
        // await app.runSchedule('run');
        console.log('beforeStart')
        const dir = path.join(app.config.baseDir, 'app/model');
        app.loader.loadToContext(dir, 'model', {
            inject: app,
            caseStyle: 'upper',
            filter(model) {
                console.log(model);
                console.log(typeof model === 'function' && model.prototype instanceof app.mongoose.Model);
                console.log(typeof model === 'function');
                return true;
            },
        });
        // const modelPaths = app.loader.getLoadUnits().map(unit => path.join(unit.path, 'app/model'));
        // app.loader.loadToContext(modelPaths, 'model', {
        //     // service 需要继承 app.Service，所以要拿到 app 参数
        //     // 设置 call 在加载时会调用函数返回 UserService
        //     call: true,
        //     // 将文件加载到 app.serviceClasses
        //   });
    });

    app.once('server', (server) => {
    });


    app.on('request', (ctx) => {
    });
    app.on('response', (ctx) => {
    });
};